<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<%@include file="/WEB-INF/pages/common/head.jsp"%>
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
		<title><spring:message code="title.dictionary" /></title>
		<script type="text/javascript">
        var datagrid;
        var message =$.messager;
        var operateDialog;
        $(function() {
            datagrid=$('#datagrid').datagrid({
                url : '${path}/business/supplier_quality/quality_system/ajaxList.do',
                onLoadSuccess:function(){
                    datagrid.datagrid('clearSelections');
                }
            });
        });
        //子页面返回方法
        function returnResult(){
            operateDialog.dialog('close');
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('reload');
        }
        //判断选择单据是否是一条
        function isChooseOne(rows){
            var flag = false;
            if(rows.length >1 ) {
                message.show({
                    msg : "<spring:message code='msg.choose' arguments='"+rows.length+"'/>",
                    title : '<spring:message code='msg.tip'/>'
                });
                flag = false;
            } else if (rows.length == 0) {
                message.show({
                    msg : "<spring:message code='msg.please.choose'/>",
                    title : '<spring:message code='msg.tip'/>'
                });
                flag = false;
            }else{
                flag = true;
            }
            return flag;
        }
        function search_() {
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('load', imonJYRH.serializeObject($("#tableForm *")));
        }
        function reset_(){
            $("#tableForm *").each(function(){
                $(":input:not(:checkbox,:radio)",this).val("");
            });
        }
         function modify_(){
            var rows = datagrid.datagrid("getSelections");
            if(!isChooseOne(rows)){return;}
            var href = '${path}/business/supplier_quality/quality_system/modifyUI.do?id='+rows[0]['id'];
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.modify'/>',
                width:1000,height:520
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
        
          function add_() {
            var href = '${path}/business/supplier_quality/quality_system/addUI.do';
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.create'/>',
                width:1000,height:520
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
        
          function delete_(){
            var ids = getSelectedIds();
            
             $.messager.confirm(
                    '<spring:message code='msg'/>',
                    '<spring:message code='msg.confirm.delete'/>',
                    function(r){
                        if (r && null!=ids){
                            imonJYRH.showZone();
                            $.ajax({
                                url : imonJYRH.url("${path}/business/supplier_quality/quality_system/ajaxDelete.do"),
                                cache : false,
                                data :{'ids':ids.join(',')},
                                success : function(reMsg) {
                                    if(reMsg.success){
                                        search_();
                                        message.show({
                                            msg : reMsg.msg,
                                            title : '<spring:message code='msg.tip'/>',
                                            showType:'slide'
                                        });
                                    }else{
                                        message.alert('<spring:message code='msg.tip'/>',reMsg.msg);
                                    }
                                    imonJYRH.hideZone();
                                }
                            });
                        }
                    });
        }
        
        function getSelectedIds(){
            var rows = datagrid.datagrid("getSelections");
            if (rows.length > 0) {
                var ids = [];
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                return ids;
            }else{
                $.messager.alert('<spring:message code='msg.error'/>','<spring:message code='msg.delete'/>','error');
                return null;
            }
        }
    	/**
    	 *质量体系导出
    	 */
		function export_() {
			  var rows = datagrid.datagrid("getSelections");
	 	    var id ="";
	         if (rows.length > 0) {
	         	if(rows.length==1){
	                  for ( var i = 0; i < rows.length; i++) {
	                      id=rows[i].id;
	                  }
	                  $.messager.confirm('提示', '确定导出数据？', function(r) {
	      				if (r&&id!=null) {
	      					var url = "${path}/excel/qualitySystemExcel/exportExcel.do";
	      					url += "?id=" + id;
	      					$("#qualitySystemForm").attr("action", url).submit();
	      				} else {
	      					return;
	      				}
	      			});
	         	}else{
	         		$.messager.alert('<spring:message code='msg.error'/>','请选择一项进行导出','error');
	         		return
	         	}
	         }else{
	             $.messager.alert('<spring:message code='msg.error'/>','请选择','error');
	             return;
	         }
		}
       	/**
    	 *发送邮件
    	 */
    	function sendMail() {
    		var rows = datagrid.datagrid("getRows");
              if (rows.length > 0) {
<%--                       for ( var i = 0; i < rows.length; i++) {--%>
<%--                           ids.push(rows[i].id);--%>
<%--                           var date1=formatDate();--%>
<%--                           var date2=rows[i].expiredDates;--%>
<%--                           var time1 = new Date(date1.replace("-", "/").replace("-", "/"));--%>
<%--                           var time2 = new Date(date2.replace("-", "/").replace("-", "/"));--%>
<%--                           if(time1<time2){--%>
<%--                            message.alert('<spring:message code='msg.tip'/>','证书未过期，请选择');--%>
<%--                           return;--%>
<%--                           }--%>
<%--                       }--%>
                       $.messager.confirm('提示', '确定向供应商发送邮件？', function(r) {
           				if (r) {
           			      imonJYRH.showZone();
                          $.ajax({
                              url : imonJYRH.url("${path}/business/supplier_quality/quality_system/ajaxSendMail.do"),
                              cache : false,
                              success : function(reMsg) {
                                  if(reMsg.success){
                                      message.show({
                                          msg : reMsg.msg,
                                          title : '发送成功',
                                          showType:'slide'
                                      });
                                  }else{
                                      message.alert('<spring:message code='msg.tip'/>',reMsg.msg);
                                  }
                                  imonJYRH.hideZone();
                              }
                          });
           				} else {
           					return;
           				}
           			});
              }else{
                  $.messager.alert('<spring:message code='msg.error'/>','没有数据','error');
                  return;
              }
    	}
    function   formatDate(){    
        var d=new Date();  //  获取当前日期    
    	var str=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();       
    	return str;
    }
    function dialogSupplier_(){
            var href = '${path}/basedata/supplier/dialogUI.do';
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.dialog.choose'/>',
                width : 650,
                height : 400
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
     function dialogSupplierReturn(row){
            $("#supplierId").val(row['id']);
            $("#supplierCode").val(row['code']);
            $("#supplierName").val(row['name']);
            operateDialog.dialog('close');
        }
    </script>
	</head>
	<body class="easyui-layout">
		<form id="qualitySystemForm" method="post">
			<div data-options="region:'north'" style="overflow: hidden;">
				<div class="datagrid-toolbar" style="height: auto;">
					<br />
					<fieldset>
						<table width="100%" id="tableForm">
							<tr>
								<td align="right">
									SupplierCode供应商编码：
								</td>
								<td>
									<input type="hidden" id='supplierId' name="supplierId" />
									<input type="text" id="supplierCode"
										onclick="dialogSupplier_();" readonly="true" />
								</td>
								<td align="right">
									SupplierName供应商名称：
								</td>
								<td>
									<input type="text" id="supplierName" style="width: 180px;"
										disabled />
								</td>
								<!-- <td align="right">Supplier Type供应商类型：</td>
                    <td>
                        <input type="text"  name="type" disabled/>
                    </td>-->
							</tr>
						</table>
					</fieldset>
					<br />
				</div>
			</div>
			<div data-options="region:'center'">
				<div id="tb">
					<a class="easyui-linkbutton" href="javascript:void(0);"
						plain="true" iconCls="icon-search" onclick="search_();"><spring:message
							code="bar.command.search" /> </a>
					<a class="easyui-linkbutton" href="javascript:void(0);"
						plain="true" iconCls="icon-undo" onclick="reset_();"><spring:message
							code="bar.command.reset" /> </a>
					<a class="easyui-linkbutton" href="javascript:void(0);"
						plain="true" iconCls="icon-add" onclick="add_();">Add新增</a>
					<a class="easyui-linkbutton" href="javascript:void(0);"
						plain="true" iconCls="icon-edit" onclick="modify_();" _>Modify修改</a>
					<a class="easyui-linkbutton" href="javascript:void(0);"
						plain="true" iconCls="icon-cancel" onclick="delete_();"><spring:message
							code="bar.command.delete" /> </a>
					<!--<a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-import">Import导入</a>-->
					<a class="easyui-linkbutton" href="javascript:void(0);"
						plain="true" iconCls="icon-export" onclick="export_();">Export导出</a>
					<a class="easyui-linkbutton" href="javascript:void(0);"
						plain="true" iconCls="icon-mail" onclick="sendMail()">向证书过期的供应商发送邮件</a>
				</div>
				<table class="easyui-datagrid" toolbar="#tb" pagination="true"
					fit="true" nowrap="false" id="datagrid">
					<thead>
						<tr>
							<th field="ck" checkbox="true"></th>
							<th field="supplierCode" width="80" align="center">
								SupplierCode
								<br />
								供应商编码
							</th>
							<th field="supplierName" width="100" align="center">
								SupplierName
								<br />
								供应商名称
							</th>
							<th field="value" width="100" align="center">
								EvaluationValue
								<br />
								得分
							</th>
							<th field="certificationType" width="100" align="center">
								certificationType
								<br />
								认证类型
							</th>
							<!--<th field="3" width="100" align="center">ISO/TS 16949</th>
            <th field="4" width="60" align="center">ISO 9001</th>
            <th field="5" width="50" align="center">Others</th>
            <th field="6" width="70" align="center">NoCertified<br/>无认证</th>-->
							<th field="certificationDates" width="120" align="center">
								certificationDate
								<br />
								认证日期
							</th>
							<th field="expiredDates" width="160" align="center">
								certificationExpireDate
								<br />
								认证到期日期
							</th>
							<th field="updateRequired" width="100" align="center">
								UpdateRequired
								<br />
								请求续订
							</th>
							<th field="selfAssessment" width="100" align="center">
								SelfAssessment
								<br />
								自我测评
							</th>
							<th field="contactPerson" width="100" align="center">
								ContactPerson
								<br />
								联系人
							</th>
							<th field="selfAssessmentDates" width="100" align="center">
								DateOfSelfAssessment
								<br />
								自我测评日期
							</th>
							<th field="comment" width="100" align="center">
								Comment
								<br />
								评论
							</th>
							<th field="mailDates" width="80" align="center">
								MailDate
								<br />
								发送邮件日期
							</th>
						</tr>
					</thead>
				</table>
			</div>
		</form>
		<div id="operateDialog" class="easyui-dialog"
			style="width: 880px; height: 520px;"
			data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
			<iframe scrolling="auto" id='operateIFrame' frameborder="0" src=""
				style="width: 100%; height: 100%;" />
		</div>
	</body>
</html>
